home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / usenet / volume2 / conquest / part01 next >
Encoding:
Internet Message Format  |  1987-10-26  |  55.5 KB

  1. Path: uunet!tektronix!tekgen!tekred!games-request
  2. From: games-request@tekred.TEK.COM
  3. Newsgroups: comp.sources.games
  4. Subject: v02i058:  conquest - middle earth multi-player game, Part01/05
  5. Message-ID: <1741@tekred.TEK.COM>
  6. Date: 26 Oct 87 19:01:49 GMT
  7. Sender: billr@tekred.TEK.COM
  8. Lines: 1771
  9. Approved: billr@tekred.TEK.COM
  10.  
  11. Submitted by: ihnp4!mhuxd!smile (E.BARLOW)
  12. Comp.sources.games: Volume 2, Issue 58
  13. Archive-name: conquest/Part01
  14.  
  15.     [The following is from the author...   -br]
  16. [[This is the first posting of my multi player game "conquest".  
  17. CONQUEST is a middle earth multi-player computer game in which each
  18. player is the leader of a nation, composed of people (humans, orcs,
  19. elves, dwarves), resources, and land.  Several neat features are
  20. supported, chiefly non player countries and magic powers.
  21.  
  22. The game is somewhat like the game "empire", so I would think that any
  23. news articles about it should go to either rec.games.empire or,
  24. preferably, rec.games.]]
  25.  
  26. #! /bin/sh
  27. # This is a shell archive.  Remove anything before this line, then unpack
  28. # it by saving it into a file and typing "sh file".  To overwrite existing
  29. # files, type "sh file -c".  You can also feed this as standard input via
  30. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  31. # will see the following message at the end:
  32. #        "End of archive 1 (of 5)."
  33. # Contents:  README MANIFEST makeworld.c npc.c
  34. # Wrapped by billr@tekred on Mon Oct 26 10:33:02 1987
  35. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  36. if test -f README -a "${1}" != "-c" ; then 
  37.   echo shar: Will not over-write existing file \"README\"
  38. else
  39. echo shar: Extracting \"README\" \(8579 characters\)
  40. sed "s/^X//" >README <<'END_OF_README'
  41. X
  42. X            NOTES TO INSTALLER OF CONQUEST
  43. X
  44. XWhat you have here is a copyrighted beta test version of CONQUEST.  Included
  45. Xin this file are the following:
  46. X
  47. X    1) A Brief Description of Conquest
  48. X    2) Installation (unpacking) Instructions
  49. X    3) A Manifest (after you have installed it)
  50. X    4) Compilation Instructions
  51. X    5) administration instructions
  52. X    6) execution instructions (how to play)
  53. X    7) a list of further enhancements I am planning on making
  54. X    8) Bug list and unimplemented options
  55. X
  56. XRemember this is an BETA version, not to be redistributed, and
  57. Xprobably has bugs.  Any comments and bug reports would be appreciated.
  58. X
  59. X-----------------------------------------------------------
  60. XI   A Brief Description of Conquest
  61. X-----------------------------------------------------------
  62. X
  63. XREAD FILE .help FOR A DESCRIPTION OF CONQUEST.  The help file can be
  64. Xread in nice format by using "conquest -h" after compilation.
  65. X
  66. X-----------------------------------------------------------
  67. XII  Installation (unpacking) Instructions
  68. X-----------------------------------------------------------
  69. X
  70. XThis program came in three shar scripts, which can be unpacked
  71. Xby using "sh filename".  If you are reading this, you know this.
  72. X
  73. X-----------------------------------------------------------
  74. XIII A Manifest (after you have unpacked it) of Conquest Files is a follows
  75. X    /bin/ls -aFC should look like this
  76. X-----------------------------------------------------------
  77. X
  78. XTHE FOLLOWING 2 FILES SHOULD BE MODIFIED TO REFLECT THE TYPE OF GAME YOU WISH
  79. X
  80. Xheader file: header.h   
  81. Xmakefile: Makefile
  82. X
  83. Xsuport files: .nations .help README 
  84. X
  85. XC code: 
  86. X    combat.c      forms.c       main.c        newlogin.c    update.c
  87. X    commands.c    io.c          makeworld.c   npc.c
  88. X    execute.c     magic.c       move.c        reports.c
  89. X
  90. X-----------------------------------------------------------
  91. XIV  Compilation Instructions
  92. X-----------------------------------------------------------
  93. X
  94. XBrowse the file header.h.  This sets up configurable parameters for the
  95. Xgame.  This program should be easy to compile (although it never really is -- 
  96. XI have tried to make it as easy as possible). If there are problems check 
  97. Xthe following.
  98. X
  99. X1.  Sometimes termcap/termlib... are not on systems.  You will know this
  100. X    is the error if all the '.c' files compile but will not compile together.
  101. X    Unreferenced symbol errors will occur.  Try changing the name
  102. X    of the library (or eliminating it on some systems) on the final compile 
  103. X    and link step.
  104. X2.  Find your nearest unix guru and ask him.
  105. X
  106. X-----------------------------------------------------------
  107. XV   administration instructions
  108. X-----------------------------------------------------------
  109. X
  110. XNow that you have compiled it, this is how you administer the game.
  111. XI recommend following these instructions once yourself in a mock game 
  112. X(ie. no other players) for a few turns to get things straight.  Then you 
  113. Xcan add other players.
  114. X
  115. XYou can type the following commands to help administer the game
  116. X
  117. XMake clobber:  clobber everything but the source (destroys executable)
  118. XMake clean:    clean up objects (does not destroy executable)
  119. XMake install:    Installs executable & data in appropriate directories (header.h)
  120. XMake docs:    Creates documentation from help file
  121. X
  122. XMake lint:    produces lint output for the game.  
  123. Xrun:        read it, it permits you to run the update automatically
  124. X
  125. XThis is the command line format for conquest:
  126. X    Cmd line format: conquest [-maxhp]
  127. X        (no options) play the game
  128. X        -m   make a world (file '.data' must not exist, must be god)
  129. X        -a   add new player (must be god)
  130. X        -x   execute program (must be god)
  131. X        -h   print help text
  132. X        -p   print a map to stdout (must be god)
  133. X
  134. XAgain, prior to the compile, you should have browsed the header.h file.  
  135. XFollow the comments.  
  136. X
  137. XThen create the world via:
  138. X    <conquest -m>    this will make your world.  Try it.
  139. X             This also sets up npc nations as per the .nations file
  140. X             npc stats can be adjusted by editing .nations
  141. X             prior to making the world.  Non player nations have
  142. X             the same password as god.
  143. X
  144. XAdd 0 or more players via
  145. X    <conquest -a>    which should be self explanitory
  146. X
  147. XNow type <conquest> and log in as <god> with the appropriate super user
  148. Xpassword.  
  149. X
  150. XLearn the commands (Type '?' to get help) & play around to get your 
  151. Xsyntax right.
  152. X
  153. XTry logging in as either a player or non player nation (they use the super
  154. Xuser passwd) and noticing any differences.
  155. X
  156. XNow move around on the map and learn where the players are
  157. Xpositioned.  If there is a problem (they are surrounded by water...), 
  158. Xuse the redesignate command to change elvation or vegitation. 
  159. XIn the worst case, god can destroy a nation
  160. Xwith 'c', the change nation command.  Once you
  161. Xthink the game will be fair, it is time to allow players to proceed.
  162. X
  163. XNow you are all set -- play via 
  164. X    <conquest>
  165. X
  166. Xand update (every midnight via at...) with
  167. X    <conquest -x>
  168. Xan "at" script to do this is contained in the shell script "run".
  169. X
  170. XI have attempted to give enough aides to playing that it should
  171. Xtake no longer than fifteen minutes per day to play.  If it takes
  172. Xmore, something is wrong.
  173. X
  174. X*WARNING*  IF YOU REMOVE THE .data FILE, REMEMBER TO ZERO THE .execute
  175. Xfile or the world will be screwed up when you recreate it.  This will
  176. Xcause you to spend hours browsing the source code and result in untold
  177. Xfrustration (I speak from experience).
  178. X
  179. X--------------------------------------------------------------------
  180. XVI a list of further enhancements/bug fixes I am planning on making
  181. X--------------------------------------------------------------------
  182. X
  183. XTrade is unimplemented
  184. XNaval combat and movement has not been system tested
  185. XCities do not have garrison armies
  186. XOnly one type of soldier and one type of warship allowed
  187. XVarious Scoreing techniques are not implemented
  188. XCharacter Classes are not fully implemented
  189. X
  190. X---------------------------------------------------------------------------
  191. XVII The following are future changes to myh magic system (Comments, Ideas?)
  192. X---------------------------------------------------------------------------
  193. X
  194. X            ADDITIONAL (UNIMPLEMENTED) MAGIC POWERS   
  195. X
  196. XWARLOCK      Use all level 1 Spells  (see separate)
  197. XSORCERER     Use all level 2 Spells  (see separate)
  198. XWYZARD       Use all level 3 Spells  (see separate)
  199. XSEA LORD:    2x sea movement/combat, storms not sink ships, (HUMANS ONLY)
  200. XESKIMO:      Ice sectors = 0 move, have vegitation 9, and give +30% combat 
  201. XDRUID:       Wood/Jungle sectors = 0 move, have vegitation 9, and +30% combat 
  202. XTYRANT:      Costs nothing to enlist and support troops. 
  203. X
  204. X                MAGIC ARTIFACTS 
  205. X
  206. X            1)KINGS SWORD  (KNOWALL)
  207. X            2)LONG SPEAR   (CAPTAIN)
  208. X            3)SILVER ARMOR (CAPTAIN)
  209. X            4)BLACK SHIELD (DEFENDER)
  210. X            5)EVIL CLOAK   (VOID)
  211. X            6)DEMON WAND   (MINOR MONSTER)
  212. X            7)GREAT HELM   (HIDDEN)
  213. X            8)DWARVEN PYRAMID (MINER)
  214. X            9)BLACK RING   (SPY)
  215. X            10)SEA FLASK   (SEA LORD)
  216. X            11)GREAT HAMMER (MINER)
  217. X            12)ELVEN BOW   (ARCHER)
  218. X            13)DEATH SCEPTER  (VAMPIRE)
  219. X            14)GOLD CROWN  (MINOR MONSTER,DESTROYER)
  220. X            15)FIRE BOOTS  
  221. X            16)GREAT THRONE (DESTROYER)
  222. X            17)FROST BELT (ICE LORD)
  223. X            18)WOOD STAFF (WOOD LORD)
  224. X            19)DARK HORN 
  225. X            20)TREE OF LIFE (URBAN)
  226. X
  227. X                WYZARDRY
  228. X
  229. XThere are three spell levels: Warlock, Sorcerer, and Wizard.  Spells can
  230. Ximitate any of the powers listed above, and can do single shot impacts.
  231. XSpells are used as follows.  First the user is asked what spell they wish
  232. Xto use.  These spells effect either the nations temporary magic level, or
  233. Xspecific areas.
  234. X
  235. X                                                    Jewel pts:level
  236. XUse a Magic Item                                       :Free    : none
  237. X
  238. XKill 50% of civilians in non city sector         :    :
  239. XKill all civilians in non city sector            :    :
  240. XKill 50% of civilians in city sector             :    :
  241. XDestroy all civilians in city sector             :    :
  242. XFreeze all movement by 1 npc (AMOVE=0)             :    :
  243. XCurse -- -2 to movement of 1 PC nations armies         :    :
  244. XCurse -- -2 to movement of 1 NPC nations armies        :    :
  245. Xfriendly (+1) with 1 npc nation                :    :
  246. XBuild 1 point of fort walls                  :    :
  247. XSummon dead army (VAMPIRE ONLY, 500 men)        :    :
  248. XSummon dead legion (VAMPIRE ONLY, 1500 men)        :    :
  249. XFriendship (+2) with 1 npc nation            :    :
  250. XAnimosity (-1) between 2 other nations             :    :
  251. XHatred (-2) between 2 other nations                 :    :
  252. XWarm Permanently  (+1 vegitation to sector)        :    :
  253. XFreeze Permanently (-1 vegitation to sector)        :    :
  254. XBreech forts walls                    :    :
  255. XTakeover NPC Nation Of Same Race             :    :
  256. XTeleport one army (up to 100 men)            :    :    
  257. XTeleport one army (up to 1000 men)            :    :
  258. XTeleport one army (any # men)                :    :
  259. XTransmute iron to jewels                 :    :
  260. XCloak activity                        :    :
  261. XCause fear (1 oposing army to home capitol)        :    :    
  262. END_OF_README
  263. if test 8579 -ne `wc -c <README`; then
  264.     echo shar: \"README\" unpacked with wrong size!
  265. fi
  266. # end of overwriting check
  267. fi
  268. if test -f MANIFEST -a "${1}" != "-c" ; then 
  269.   echo shar: Will not over-write existing file \"MANIFEST\"
  270. else
  271. echo shar: Extracting \"MANIFEST\" \(744 characters\)
  272. sed "s/^X//" >MANIFEST <<'END_OF_MANIFEST'
  273. X   File Name        Archive #    Description
  274. X-----------------------------------------------------------
  275. X .help                     4    
  276. X .nations                  5    
  277. X DIST-NOTE                 5    
  278. X MANIFEST                  1    This shipping list
  279. X Makefile                  4    
  280. X README                    1    
  281. X combat.c                  2    
  282. X commands.c                3    
  283. X execute.c                 4    
  284. X forms.c                   5    
  285. X header.h                  5    
  286. X io.c                      5    
  287. X magic.c                   2    
  288. X main.c                    3    
  289. X makeworld.c               1    
  290. X move.c                    4    
  291. X newlogin.c                2    
  292. X npc.c                     1    
  293. X reports.c                 3    
  294. X run                       3    
  295. X update.c                  4    
  296. END_OF_MANIFEST
  297. if test 744 -ne `wc -c <MANIFEST`; then
  298.     echo shar: \"MANIFEST\" unpacked with wrong size!
  299. fi
  300. # end of overwriting check
  301. fi
  302. if test -f makeworld.c -a "${1}" != "-c" ; then 
  303.   echo shar: Will not over-write existing file \"makeworld.c\"
  304. else
  305. echo shar: Extracting \"makeworld.c\" \(19675 characters\)
  306. sed "s/^X//" >makeworld.c <<'END_OF_makeworld.c'
  307. X/*conquest is copyrighted 1986 by Ed Barlow.
  308. X *  I spent a long time writing this code & I hope that you respect this.  
  309. X *  I give permission to alter the code, but not to copy or redistribute
  310. X *  it without my explicit permission.  If you alter the code, 
  311. X *  please document changes and send me a copy, so all can have it.  
  312. X *  This code, to the best of my knowledge works well,  but it is my first
  313. X *  'C' program and should be treated as such.  I disclaim any
  314. X *  responsibility for the codes actions (use at your own risk).  I guess
  315. X *  I am saying "Happy gaming", and am trying not to get sued in the process.
  316. X *                                                Ed
  317. X */
  318. X
  319. X/*Create a world*/
  320. X
  321. X/*DEFINE TEMPORARY VARIABLES FROM MAKEFILE*/
  322. X#include <ctype.h>
  323. X#include <stdio.h>
  324. X#include "header.h"
  325. X
  326. X#define HALF 2
  327. X#define LAND 3
  328. X
  329. Xextern short country;
  330. Xint area_map[MAXX][MAXY];/*Value Map of Areas*/
  331. Xint type[MAPX][MAPY];
  332. X
  333. Xmakeworld()
  334. X{
  335. X    register int i,j;
  336. X    register int x,y;
  337. X    int n; /*count used in string searches*/
  338. X    float avvalue; /*Average water tvalue of sectors*/
  339. X    int number[5]; /*Number of sectors with type=[0-4]*/
  340. X    char passwd[12];
  341. X    int alloc = NUMAREAS * 2;/*Value Allocated*/
  342. X    int place[MAXX][MAXY] ;/*Temporary matrix to see if an area is placed*/
  343. X    int X, Y;
  344. X    int X1,Y1;
  345. X    int X2,Y2;
  346. X    int valid;
  347. X    int nranges;
  348. X    int rnd;
  349. X    int tempfd;
  350. X
  351. X    /*abort if DATAFILE currently exists*/
  352. X    if(tempfd=open(DATAFILE,0)!=-1) {
  353. X        printf("ABORTING: File %s exists-->a game is in progress\n",DATAFILE);
  354. X        printf("to proceed, you must remove the existing game\n");
  355. X        printf("file. This will, of course, destroy that game\n");
  356. X        printf("\nIf you do remove that file, be aware that you need");
  357. X        printf("\nto also zero the .execute file");
  358. X        exit(1);
  359. X    }
  360. X
  361. X    printf("please enter new super user password (remember this!):");
  362. X    scanf("%s",passwd);
  363. X    getchar();
  364. X    printf("\nplease reenter password:");
  365. X    scanf("%s",ntn[0].passwd);
  366. X    getchar();
  367. X    if((strlen(ntn[0].passwd)<2)||(strncmp(passwd,ntn[0].passwd,PASSLTH)!=0)) {
  368. X        printf("\ninvalid super user password\n");
  369. X        exit(1);
  370. X    }
  371. X    else printf("super user password is %s\n",ntn[0].passwd);
  372. X    strncpy(ntn[0].passwd,crypt(passwd,SALT),PASSLTH);
  373. X
  374. X    printf("\nThe world will now be created...Your super user login");
  375. X    printf("\nwill be 'god'.  All non player countries that were");
  376. X    printf("\ncreated when the world was created from the file .nations");
  377. X    printf("\nwill have the same password as the one you just entered");
  378. X    printf("\nto add player nations, use <conquest -a>");
  379. X    printf("\nhave fun");
  380. X
  381. X    printf("\n\ncreating world\n");
  382. X    /*initialize variables */
  383. X    avvalue = (((float) PWATER/25.0)); /*Average water tvalue of sectors*/
  384. X    for(i=0;i<MAXX;i++) for(j=0;j<MAXY;j++) {
  385. X        place[i][j]=0;
  386. X        area_map[i][j]=0;
  387. X    }
  388. X    for(i=0;i<MAPX;i++) for(j=0;j<MAPY;j++) sct[i][j].vegitation=NONE;
  389. X
  390. X    for(i=0;i<5;i++) number[i] = NUMAREAS/5;  /*areas with type=[i]*/
  391. X    number[2]=NUMAREAS - 4*number[0]; /*correct for roundoff*/
  392. X
  393. X    /*determine # of area types to areas*/
  394. X    for(i=0;i<250;i++) {
  395. X        if((avvalue*NUMAREAS)>alloc) {
  396. X            /*have not allocated high enough so Allocate more */
  397. X            x = rand()%4;   /*0 to 3*/
  398. X            if(number[x]>0) {
  399. X                number[x] = number[x] - 1;
  400. X                number[x+1] = number[x+1] + 1;
  401. X                alloc = alloc + 1;
  402. X            }
  403. X        }
  404. X        else    {
  405. X            /*have allocated too much  Allocate less */
  406. X            x = (rand()%4) +1; /*1 to 4*/
  407. X            if(number[x]>0) {
  408. X                number[x] = number[x] - 1;
  409. X                number[x-1] = number[x-1] + 1;
  410. X                alloc = alloc - 1;
  411. X            }
  412. X        }
  413. X    }
  414. X
  415. X    i=0;
  416. X    while((number[4]>0)&&(i<500)) {
  417. X        i++;
  418. X        /*place a full land sector anywhere but on edge*/
  419. X        X = ((rand()%(MAXX-2))+1); /*1 to MAXX-2)*/
  420. X        Y = ((rand()%(MAXY-2))+1); /*1 to MAXY-2)*/
  421. X        if(place[X][Y] == 0) {
  422. X            place[X][Y]=1;
  423. X            area_map[X][Y]=4;
  424. X            number[4]=number[4] - 1;
  425. X            /*place surrounding sectors*/
  426. X            if(place[X+1][Y] == 0) {
  427. X                rnd = rand()%100 + 1; /*1 to 100*/
  428. X                if((rnd<25) && (number[4]>0)) {
  429. X                    area_map[X+1][Y]=4;
  430. X                    number[4]=number[4]-1;
  431. X                    place[X+1][Y]=1;
  432. X                }
  433. X                if(rnd>25 && number[3]>0) {
  434. X                    area_map[X+1][Y]=3;
  435. X                    number[3]=number[3]-1;
  436. X                    place[X+1][Y]=1;
  437. X                }
  438. X            }
  439. X            if(place[X-1][Y] == 0) {
  440. X                rnd = rand()%100 + 1 ; /*(1 to 100)*/
  441. X                if(rnd<25 && number[4]>0) {
  442. X                    area_map[X-1][Y]=4;
  443. X                    number[4]=number[4]-1;
  444. X                    place[X-1][Y]=1;
  445. X                }
  446. X                if(rnd>25 && number[3]>0) {
  447. X                    area_map[X-1][Y]=3;
  448. X                    number[3]=number[3]-1;
  449. X                    place[X-1][Y]=1;
  450. X                }
  451. X            }
  452. X            if(place[X][Y+1] == 0) {
  453. X                rnd = rand()%100 + 1 ; /*(1 to 100)*/
  454. X                if(rnd<25 && number[4]>0) {
  455. X                    area_map[X][Y+1]=4;
  456. X                    number[4]=number[4]-1;
  457. X                    place[X][Y+1]=1;
  458. X                }
  459. X                if(rnd>25 && number[3]>0) {
  460. X                    area_map[X][Y+1]=3;
  461. X                    number[3]=number[3]-1;
  462. X                    place[X][Y+1]=1;
  463. X                }
  464. X            }
  465. X            if(place[X][Y-1] == 0) {
  466. X                rnd = rand()%100 + 1 ; /*(1 to 100)*/
  467. X                if(rnd<25 && number[4]>0) {
  468. X                    area_map[X][Y-1]=4;
  469. X                    number[4]=number[4]-1;
  470. X                    place[X][Y-1]=1;
  471. X                }
  472. X                if(rnd>25 && number[3]>0) {
  473. X                    area_map[X][Y-1]=3;
  474. X                    number[3]=number[3]-1;
  475. X                    place[X][Y-1]=1;
  476. X                }
  477. X            }
  478. X        }
  479. X    }
  480. X
  481. X    /* place all other areas*/
  482. X    for(X=0;X<MAXX;X++) for(Y=0;Y<MAXY;Y++) {
  483. X        while(place[X][Y] == 0) {
  484. X            rnd = rand()%5; /*(0 to 4)*/
  485. X            if(number[rnd]>0) {
  486. X                area_map[X][Y]=rnd;
  487. X                number[rnd]=number[rnd]-1;
  488. X                place[X][Y]=1;
  489. X            }
  490. X        }
  491. X    }
  492. X
  493. X    /*ALL AREAS PLACED, NOW DETERMINE SECTOR TYPE
  494. X *fill in each area with sectors
  495. X *      1)   water
  496. X *      2)   water with major islands (25% land)
  497. X *      3)   50/50 water/land 
  498. X *      4)   land with major water (75% Land)
  499. X *      5)   land 
  500. X */
  501. X    for(Y=0;Y<MAXY;Y++) for(X=0;X<MAXX;X++) {
  502. X        /*fill in edges*/
  503. X        fill_edge(X,Y);
  504. X        /*fill in center*/
  505. X        for(i=1;i<7;i++) {
  506. X            for(j=1;j<7;j++) switch(area_map[X][Y]){
  507. X
  508. X            case 0:
  509. X                if((rand()%100) < 95) type[X*8+i][Y*8+j]=WATER;
  510. X                else type[X*8+i][Y*8+j]=HALF;
  511. X                break;
  512. X            case 1:
  513. X                if(rand()%2 == 0) type[X*8+i][Y*8+j]=WATER;
  514. X                else type[X*8+i][Y*8+j]=HALF;
  515. X                break;
  516. X            case 2:
  517. X                if (rand()%2 == 0) type[X*8+i][Y*8+j]=WATER;
  518. X                else type[X*8+i][Y*8+j]=LAND;
  519. X                break;
  520. X            case 3:
  521. X                if (rand()%2 == 0) type[X*8+i][Y*8+j]=LAND;
  522. X                else type[X*8+i][Y*8+j]=HALF;
  523. X                break;
  524. X            case 4:
  525. X                if ((rand()%100) < 95) type[X*8+i][Y*8+j]=LAND;
  526. X                else type[X*8+i][Y*8+j]=HALF;
  527. X                break;
  528. X            default:
  529. X                printf("ERROR");
  530. X            }
  531. X        }
  532. X    }
  533. X
  534. X    /*calculate all 50% areas*/
  535. X    for(X=0;X<MAPX;X++) for(Y=0;Y<MAPY;Y++) {
  536. X        if(type[X][Y] == HALF)
  537. X            if(rand()%2 == 0) {
  538. X                type[X][Y] = LAND;
  539. X            }
  540. X            else type[X][Y] = WATER;
  541. X    }
  542. X
  543. X
  544. X    /*Adjust world given sectors as land or sea, place vegitation, designation, 
  545. X and altitude */
  546. X
  547. X    for(i=0;i<MAPX;i++) for(j=0;j<MAPY;j++)
  548. X        if(type[i][j]==LAND) sct[i][j].altitude = CLEAR;
  549. X        else sct[i][j].altitude = WATER;
  550. X
  551. X    /*place mountain ranges */
  552. X
  553. X    nranges=(rand()%10+3)*avvalue;
  554. X    printf("%d mountain ranges to be placed",nranges);
  555. X
  556. X    while(nranges>0) {
  557. X        /*Place one range randomly*/
  558. X        X1 = rand()%(MAPX-6);
  559. X        Y1 = rand()%(MAPY-6);
  560. X        if((type[X1][Y1]==LAND)&&(type[X1+1][Y1+1]==LAND)&&(type[X1+1][Y1]==LAND)&&(type[X1][Y1+1]==LAND)&&(type[X1+2][Y1+2]==LAND)) {
  561. X            /*place second endpoint */
  562. X            valid = 0;
  563. X            i=0;
  564. X            nranges--;
  565. X            while((valid==0) && (i<500)) {
  566. X                i++;
  567. X                X2 = (rand()%7) + X1;
  568. X                Y2 = (rand()%7) + Y1;
  569. X                if(type[X2][Y2] == LAND) {
  570. X                    valid = 1;
  571. X                    /*fill in mountain range*/
  572. X                    for(x=X1;x<=X2;x++) {
  573. X                        if(X1<X2) y=((Y2-Y1)*(x-X1)/(X2-X1))+Y1;
  574. X                        else y=Y1;
  575. X                        if(type[x][y] == LAND)
  576. X                            if(rand()%100>80) sct[x][y].altitude=PEAK;
  577. X                            else sct[x][y].altitude=MOUNTAIN;
  578. X                        if(type[x][y+1] == LAND) {
  579. X                            rnd=rand()%100+1;
  580. X                            if(rnd>90) sct[x][y+1].altitude=PEAK;
  581. X                            else if(rnd>50) sct[x][y+1].altitude=MOUNTAIN;
  582. X                            else if(rnd>20) sct[x][y+1].altitude=HILL;
  583. X                        }
  584. X                        if(type[x][y-1] == LAND ) {
  585. X                            rnd=rand()%100+1;
  586. X                            if(rnd>90) sct[x][y-1].altitude=PEAK;
  587. X                            else if(rnd>50) sct[x][y-1].altitude=MOUNTAIN;
  588. X                            else if(rnd>20) sct[x][y-1].altitude=HILL;
  589. X                        }
  590. X                        if(type[x][y-2] == LAND ) {
  591. X                            rnd=rand()%100+1;
  592. X                            if(rnd>90) sct[x][y-2].altitude=MOUNTAIN;
  593. X                            else if(rnd>50) sct[x][y-2].altitude=HILL;
  594. X                        }
  595. X                        if(type[x][y+2] == LAND ) {
  596. X                            rnd=rand()%100+1;
  597. X                            if(rnd>90) sct[x][y+2].altitude=MOUNTAIN;
  598. X                            else if(rnd>50) sct[x][y+2].altitude=HILL;
  599. X                        }
  600. X                    }
  601. X                }
  602. X            }
  603. X        }
  604. X    }
  605. X
  606. X    /*fill in random hills to work out,not to left of to water*/
  607. X    for(i=1;i<NUMAREAS*3;i++) {
  608. X        x = rand()%(MAPX-1);
  609. X        y = rand()%(MAPY-1);
  610. X        if((type[x][y]==LAND)&&(type[x+1][y]==LAND))
  611. X            sct[x][y].altitude=HILL;
  612. X    }
  613. X
  614. X    /*make sure no peak or mountain is next to water*/
  615. X    for(y=1;y<MAPY-1;y++) for(x=1;x<MAPX-1;x++)
  616. X        if((sct[x][y].altitude==PEAK)||(sct[x][y].altitude==MOUNTAIN))
  617. X            for(i=0;i<=2;i++) for(j=0;j<=2;j++)
  618. X                if(sct[x+i-1][y+j-1].altitude==WATER)
  619. X                    sct[x][y].altitude=HILL;
  620. X
  621. X    /*FIGURE OUT SECTOR VEGETATION TYPE
  622. X *use sector.altitude, and sector to determine vegitation
  623. X *from water is distance from nearest water
  624. X */
  625. X
  626. X    /*char veg[]="VDW46973JSI~"*/
  627. X    /*char veg[]="VDWBLGWFJSI~"*/
  628. X
  629. X    for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
  630. X        if(type[x][y]==LAND)
  631. X        {
  632. X            sct[x][y].vegitation=(*(veg+3+rand()%5));
  633. X            /*if hill then decrement vegitation*/
  634. X            if(sct[x][y].altitude==HILL) {
  635. X                for(n=3;n<9;n++)
  636. X                    if(sct[x][y].vegitation==(*(veg+n)))
  637. X                        sct[x][y].vegitation=(*(veg+n-1));
  638. X                if(area_map[x/8][y/8]<=1) sct[x][y].vegitation=VOLCANO;
  639. X            }
  640. X            else if(sct[x][y].altitude==MOUNTAIN)
  641. X                if((rand()%6==4)&&((y>MAPY/2+8)||(y<MAPY/2-8)))
  642. X                    sct[x][y].vegitation=ICE;
  643. X                else sct[x][y].vegitation=(*(veg+2+rand()%3));
  644. X            else if(sct[x][y].altitude==PEAK)
  645. X                if((rand()%3==0)&&((y>MAPY/2+8)||(y<MAPY/2-8)))
  646. X                    sct[x][y].vegitation=ICE;
  647. X                else sct[x][y].vegitation=VOLCANO;
  648. X        }
  649. X
  650. X    /*REWORK POLEAR/EQUATORIAL sector.vegitation*/
  651. X    /*Determine which areas are North Pole and Equatorial*/
  652. X    /*char veg[]="VDW46973JSI~"*/
  653. X    /*char veg[]="VDWBLGWFJSI~"*/
  654. X    /*               012345678901*/
  655. X
  656. X    /*polar work*/
  657. X    for(x=0;x<MAPX;x++)
  658. X    {
  659. X        for(y=0;y<6;y++) if(type[x][y]==LAND)
  660. X        {
  661. X            if(rand()%4 == 0) sct[x][y].vegitation = ICE;
  662. X            else for(n=3;n<10;n++)
  663. X                if(sct[x][y].vegitation==(*(veg+n)))
  664. X                    sct[x][y].vegitation=(*(veg+(n-1)));
  665. X        }
  666. X        for(y=MAPY-7;y<MAPY;y++) if(type[x][y]==LAND)
  667. X        {
  668. X            if(rand()%4 == 0) sct[x][y].vegitation = ICE;
  669. X            else for(n=3;n<10;n++)
  670. X                if(sct[x][y].vegitation==(*(veg+n)) )
  671. X                    sct[x][y].vegitation=(*(veg+(n-1)));
  672. X        }
  673. X    }
  674. X
  675. X    /*insert equator*/
  676. X    for(y=(MAPY/2)-8;y<=(MAPY/2)+8;y++) for(x=0;x<MAPX;x++)
  677. X        if(type[x][y]==LAND)
  678. X            if(rand()%10 ==0) sct[x][y].vegitation=DESERT;
  679. X            /*increment vegitation if between Waste and Jungle*/
  680. X            else for(n=2;n<9;n++)
  681. X                if((sct[x][y].vegitation==(*(veg+n)))&&(sct[x][y].altitude==CLEAR)&&(rand()%4==0)) sct[x][y].vegitation=(*(veg+(n+1)));
  682. X
  683. X    /*char veg[]="VDW46973JSI~"*/
  684. X    /*char veg[]="VDWBLGWFJSI~"*/
  685. X    /*               012345678901*/
  686. X
  687. X    for(y=((MAPY/2)-2);y<=((MAPY/2)+2);y++) for(x=0;x<MAPX;x++)
  688. X        if((type[x][y]==LAND)&&(sct[x][y].altitude==CLEAR))
  689. X            if(rand()%10 == 0) sct[x][y].vegitation=DESERT;
  690. X            else if(rand()%10 == 0) sct[x][y].vegitation=JUNGLE;
  691. X            else if(rand()%10 == 0) sct[x][y].vegitation=SWAMP;
  692. X            /*increment vegitation again, but only Waste to Light*/
  693. X            else for(n=2;n<4;n++)
  694. X                if(sct[x][y].vegitation==(*(veg+n)))
  695. X                    sct[x][y].vegitation=(*(veg+(n+1)));
  696. X
  697. X    /*expand swamps*/
  698. X    for(y=2;y<MAPY;y++) for(x=2;x<MAPX;x++)
  699. X        if(sct[x][y].vegitation==SWAMP)
  700. X            for(i=0;i<2;i++) for(j=0;j<2;j++)
  701. X                if((type[x-i][y-j]==LAND)&&((rand()%3)==0))
  702. X                    sct[x-i][y-j].vegitation=SWAMP;
  703. X    /*expand deserts*/
  704. X    for(y=2;y<MAPY;y++) for(x=2;x<MAPX;x++)
  705. X        if(sct[x][y].vegitation==DESERT)
  706. X            for(i=0;i<2;i++) for(j=0;j<2;j++)
  707. X                if((type[x-i][y-j]==LAND)&&((rand()%3)==0))
  708. X                    sct[x-i][y-j].vegitation=DESERT;
  709. X
  710. X    /*change all volcanos to peaks */
  711. X    for(y=1;y<MAPY;y++) for(x=1;x<MAPX;x++)
  712. X        if(sct[x][y].vegitation==VOLCANO) sct[x][y].altitude=PEAK;
  713. X
  714. X    /*make sure no desert is next to water*/
  715. X    for(y=1;y<MAPY-1;y++) for(x=1;x<MAPX-1;x++)
  716. X        if(sct[x][y].vegitation==DESERT)
  717. X            for(i=0;i<=2;i++) for(j=0;j<=2;j++)
  718. X                if(sct[x+i-1][y+j-1].altitude==WATER)
  719. X                    sct[x][y].vegitation=LT_VEG;
  720. X
  721. X    /*PLACE EACH SECTOR'S RAW MATERIALS */
  722. X
  723. X    printf("\nplacing raw materials\n");
  724. X    for(y=0;y<MAPY;y++) for(x=0;x<MAPX;x++) {
  725. X
  726. X        /*gold*/
  727. X        if(rand()%10==0) sct[x][y].gold=rand()%4+4;
  728. X        else if(rand()%4==0) sct[x][y].gold=rand()%4;
  729. X        else sct[x][y].gold=0;
  730. X
  731. X        /*iron*/
  732. X        if(rand()%10==0) sct[x][y].iron=rand()%4+4;
  733. X        else if(rand()%4==0) sct[x][y].iron=rand()%4;
  734. X        else sct[x][y].iron=0;
  735. X
  736. X        /*default designations*/
  737. X        sct[x][y].designation=sct[x][y].vegitation;
  738. X
  739. X        /*default owner is unowned*/
  740. X        sct[x][y].owner=0;
  741. X    }
  742. X    populate();
  743. X    close(tempfd);
  744. X    writedata();
  745. X}
  746. X
  747. X/*fill: subroutine to fill in a square edges with land or sea*/
  748. Xfill_edge(AX,AY)
  749. X{
  750. X    /*      1)   water
  751. X *      2)   water with major islands (25% land)
  752. X *      3)   50/50 water/land 
  753. X *      4)   land with major water (75% Land)
  754. X *      5)   land 
  755. X */
  756. X    register int i;
  757. X    int edgearea, X0, Y0, X1, Y1, X2, Y2, X3, Y3, X4, Y4;
  758. X    int area;
  759. X
  760. X    X0=AX;
  761. X    Y0=AY;
  762. X    X1=X0-1;
  763. X    Y1=Y0;
  764. X    X2=X0+1;
  765. X    Y2=Y0;
  766. X    X3=X0;
  767. X    Y3=Y0-1;
  768. X    X4=X0;
  769. X    Y4=Y0+1;
  770. X
  771. X    /*NORMALIZE FOR EDGE OF WORLD*/
  772. X    if(X0==0) X1=7;
  773. X    if(X0==7) X2=0;
  774. X    if(Y0==0) Y3=7;
  775. X    if(Y0==7) Y4=0;
  776. X
  777. X    area=area_map[X0][Y0];
  778. X    /*fill in south*/
  779. X    edgearea=area_map[X4][Y4];
  780. X    if(area + edgearea > 6) for(i=0;i<8;i++) type[X0*8+i][Y0*8+7] = LAND;
  781. X    else if((area + edgearea)>3) {
  782. X        for(i=0;i<8;i++)
  783. X            if(rand()%2 == 0) type[(X0*8)+i][Y0*8+7] = LAND;
  784. X            else type[(X0*8)+i][Y0*8+7] = WATER;
  785. X    }
  786. X    else for(i=0;i<8;i++) type[(X0*8)+i][Y0*8+7] = WATER;
  787. X    /*fill in east*/
  788. X    edgearea=area_map[X2][Y2];
  789. X    if(area + edgearea > 6) for(i=0;i<8;i++) type[X0*8+7][Y0*8+i] = LAND;
  790. X    else if((area + edgearea)>3) {
  791. X        for(i=0;i<8;i++)
  792. X            if(rand()%2==0) type[X0*8+7][Y0*8+i] = LAND;
  793. X            else type[X0*8+7][Y0*8+i] = WATER;
  794. X    }
  795. X    else for(i=0;i<8;i++) type[X0*8+7][Y0*8+i] = WATER;
  796. X    /*fill in west*/
  797. X    edgearea=area_map[X1][Y1];
  798. X    if(area + edgearea > 6) for(i=0;i<=7;i++) type[X0*8][Y0*8+i] = LAND;
  799. X    else if((area + edgearea)>3) {
  800. X        for(i=0;i<8 ;i++)
  801. X            if(rand()%2==0) type[X0*8][Y0*8+i] = LAND;
  802. X            else type[X0*8][Y0*8+i] = WATER;
  803. X    }
  804. X    else for(i=0;i<8 ;i++) type[X0*8][Y0*8+i] = WATER;
  805. X    /*fill in north*/
  806. X    edgearea=area_map[X3][Y3];
  807. X    if(area + edgearea > 6) for(i=0;i<8 ;i++) type[X0*8+i][Y0*8] = LAND;
  808. X    else if((area + edgearea)>3) {
  809. X        for(i=0;i<8 ;i++)
  810. X            if(rand()%2==0) type[(X0*8)+i][Y0*8] = LAND;
  811. X            else type[(X0*8)+i][Y0*8] = WATER;
  812. X    }
  813. X    else for(i=0;i<8 ;i++) type[(X0*8)+i][Y0*8] = WATER;
  814. X}
  815. X
  816. X/* ALLOCATE POPULATIONS OF THE WORLD*/
  817. Xpopulate()
  818. X{
  819. X    int i=0,x=0,y=0,j=0;
  820. X    int nvynum=0,army2num=0,armynum=0;
  821. X    int temp;
  822. X    int cnum=0;
  823. X    FILE *fp, *fopen();
  824. X    int done=0;
  825. X    char line[80];
  826. X
  827. X
  828. X    /*randomly scatter lizard city (want in DESERTS/swamp/Ice) */
  829. X    /*don't reproduce or move. Their cities are fortified and stockpiled */
  830. X#ifdef LZARD 
  831. X    strncpy(ntn[NLIZARD].name,"lizard",10);
  832. X    strncpy(ntn[NLIZARD].leader,"dragon",10);
  833. X    strcpy(ntn[NLIZARD].passwd,ntn[0].passwd);
  834. X    ntn[NLIZARD].race=LIZARD;
  835. X    ntn[NLIZARD].mark='*';
  836. X    ntn[NLIZARD].active=2;
  837. X    ntn[NLIZARD].aplus=0;
  838. X    ntn[NLIZARD].dplus=0;
  839. X    ntn[NLIZARD].maxmove=0;
  840. X    ntn[NLIZARD].repro=0;
  841. X    ntn[NLIZARD].powers=KNOWALL;
  842. X    for(i=0;i<NTOTAL;i++) if(i!=NLIZARD) {
  843. X        ntn[NLIZARD].dstatus[i]=WAR;
  844. X        ntn[i].dstatus[NLIZARD]=WAR;
  845. X    }
  846. X
  847. X    armynum=0;
  848. X    country=NLIZARD;
  849. X    while(armynum<MAXARM-2){
  850. X        x = (rand()%MAPX);
  851. X        y = (rand()%MAPY);
  852. X        if (type[x][y] == LAND) {
  853. X            sct[x][y].designation = DCASTLE;
  854. X            sct[x][y].fortress = 5+rand()%5;
  855. X            sct[x][y].gold = 15+rand()%20;
  856. X            for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++)
  857. X                if(i>=0&&j>=0&&i<MAPX&&j<MAPX)
  858. X                    if(sct[i][j].altitude!=WATER)
  859. X                        sct[i][j].owner = NLIZARD;
  860. X            AMOVE=0;
  861. X            AXLOC=x;
  862. X            AYLOC=y;
  863. X            ASTAT=GARRISON;
  864. X            ASOLD=750+100*rand()%10;
  865. X            armynum++;
  866. X            AMOVE=8;
  867. X            AXLOC=x;
  868. X            AYLOC=y;
  869. X            ASTAT=ATTACK;
  870. X            ASOLD=750+100*rand()%10;
  871. X            armynum++;
  872. X        }
  873. X    }
  874. X    printf("%d lizards placed\n",armynum/2);
  875. X#endif
  876. X
  877. X    /* Place Brigands, Barbarians, and Nomads*/
  878. X    armynum=0;
  879. X#ifdef MONSTER 
  880. X    army2num=0;
  881. X    strcpy(ntn[NBARBARIAN].name,"bbarian");
  882. X    strcpy(ntn[NBARBARIAN].leader,"shaman");
  883. X    strcpy(ntn[NBARBARIAN].passwd,ntn[0].passwd);
  884. X    ntn[NBARBARIAN].race=BARBARIAN;
  885. X    ntn[NBARBARIAN].powers=KNOWALL;
  886. X    ntn[NBARBARIAN].mark='*';
  887. X    ntn[NBARBARIAN].active=2;
  888. X    ntn[NBARBARIAN].aplus=0;
  889. X    ntn[NBARBARIAN].dplus=10;
  890. X    ntn[NBARBARIAN].maxmove=4;
  891. X    ntn[NBARBARIAN].repro=5;
  892. X    for(i=0;i<NTOTAL;i++) if(i!=NBARBARIAN) {
  893. X        ntn[NBARBARIAN].dstatus[i]=WAR;
  894. X        ntn[i].dstatus[NBARBARIAN]=WAR;
  895. X    }
  896. X
  897. X    strcpy(ntn[NNOMAD].name,"nomad");
  898. X    strcpy(ntn[NNOMAD].leader,"kahn");
  899. X    strcpy(ntn[NNOMAD].passwd,ntn[0].passwd);
  900. X    ntn[NNOMAD].powers=KNOWALL;
  901. X    ntn[NNOMAD].race=NOMAD;
  902. X    ntn[NNOMAD].mark='*';
  903. X    ntn[NNOMAD].active=2;
  904. X    ntn[NNOMAD].aplus=10;
  905. X    ntn[NNOMAD].dplus=0;
  906. X    ntn[NNOMAD].maxmove=4;
  907. X    ntn[NNOMAD].repro=5;
  908. X    for(i=0;i<NTOTAL;i++) if(i!=NNOMAD) {
  909. X        ntn[NNOMAD].dstatus[i]=WAR;
  910. X        ntn[i].dstatus[NNOMAD]=WAR;
  911. X    }
  912. X
  913. X    strcpy(ntn[NPIRATE].name,"pirate");
  914. X    strcpy(ntn[NPIRATE].leader,"captain");
  915. X    strcpy(ntn[NPIRATE].passwd,ntn[0].passwd);
  916. X    ntn[NPIRATE].powers=KNOWALL;
  917. X    ntn[NPIRATE].race=PIRATE;
  918. X    ntn[NPIRATE].mark='*';
  919. X    ntn[NPIRATE].active=2;
  920. X    ntn[NPIRATE].aplus=20;
  921. X    ntn[NPIRATE].dplus=0;
  922. X    ntn[NPIRATE].maxmove=4;
  923. X    ntn[NPIRATE].repro=5;
  924. X    for(i=0;i<NTOTAL;i++) if(i!=NPIRATE) {
  925. X        ntn[NPIRATE].dstatus[i]=WAR;
  926. X        ntn[i].dstatus[NPIRATE]=WAR;
  927. X    }
  928. X
  929. X    temp=(rand()%10+1)*(rand()%10+1);
  930. X    for(i=0;i<temp;i++){
  931. X        /*50% chance will be on edge, else anywhere*/
  932. X        if(rand()%2==0){
  933. X            if(rand()%2==0) {
  934. X                x=(rand()%20);
  935. X                y=(rand()%20);
  936. X            }
  937. X            else {
  938. X                x=(MAPX-(rand()%20)-1);
  939. X                y=(MAPY-(rand()%20)-1);
  940. X            }
  941. X            if(rand()%2==0) x = rand()%MAPX;
  942. X            else y = rand()%MAPY;
  943. X        }
  944. X        else {
  945. X            x = rand()%MAPX;
  946. X            y = rand()%MAPY;
  947. X        }
  948. X
  949. X        /* now place people*/
  950. X        if (type[x][y]==LAND) {
  951. X            if(rand()%2==0) {
  952. X                sct[x][y].owner = NBARBARIAN;
  953. X                country=NBARBARIAN;
  954. X                AXLOC=x;
  955. X                AYLOC=y;
  956. X                ASTAT=ATTACK;
  957. X                ASOLD=200+100*rand()%10;
  958. X                armynum++;
  959. X            }
  960. X            else {
  961. X                sct[x][y].owner = NNOMAD;
  962. X                ntn[NNOMAD].arm[army2num].xloc=x;
  963. X                ntn[NNOMAD].arm[army2num].yloc=y;
  964. X                ntn[NNOMAD].arm[army2num].stat=ATTACK;
  965. X                ntn[NNOMAD].arm[army2num].sold=100+100*rand()%15;
  966. X                army2num++;
  967. X            }
  968. X        }
  969. X        else    {
  970. X            country=NPIRATE;
  971. X            NXLOC=x;
  972. X            NYLOC=y;
  973. X            NWAR=2*rand()%10;
  974. X            nvynum++;
  975. X        }
  976. X    }
  977. X    printf("all random population placed\n");
  978. X#endif
  979. X
  980. X    /*set up god but dont place*/
  981. X    strcpy(ntn[0].name,"unowned");
  982. X    strcpy(ntn[0].leader,"god");
  983. X    ntn[cnum].race=GOD;
  984. X    ntn[cnum].mark='-';
  985. X    ntn[cnum].active=0;
  986. X    ntn[cnum].location=GOD;
  987. X    ntn[cnum].powers=KNOWALL;
  988. X    cnum++;
  989. X
  990. X#ifdef NPC
  991. X
  992. X    /*open NPCSFILE file*/
  993. X    if ((fp=fopen(NPCSFILE,"r"))==NULL) {
  994. X        printf("error on read of %s file",NPCSFILE);
  995. X        return;
  996. X    }
  997. X    else printf("reading %s\n",NPCSFILE);
  998. X
  999. X    /*set up npc nation*/
  1000. X    if(fgets(line,80,fp)==NULL) done=1;
  1001. X    while(done==0) {
  1002. X        /*read and parse a new line*/
  1003. X        if(line[0]!='#') {
  1004. X            sscanf(line,"%s %s %c %c %c %hd %hd %hd %d %d %d %hd %hd",ntn[cnum].name,ntn[cnum].leader,&ntn[cnum].race,&ntn[cnum].mark,&ntn[cnum].location,&ntn[cnum].aplus,&ntn[cnum].dplus,&ntn[cnum].maxmove,&ntn[cnum].tgold,&ntn[cnum].tmil,&ntn[cnum].tciv,&ntn[cnu
  1005. Xm].repro,&ntn[cnum].active);
  1006. X            ntn[cnum].active++;
  1007. X            ntn[cnum].class=0;
  1008. X            strcpy(ntn[cnum].passwd,ntn[0].passwd);
  1009. X            country=cnum;
  1010. X            if(ntn[country].race==HUMAN){
  1011. X                ntn[country].powers=WARRIOR;
  1012. X                exenewmgk(WARRIOR);
  1013. X            }
  1014. X            else if(ntn[country].race==DWARF){
  1015. X                ntn[country].powers=MINER;
  1016. X                exenewmgk(MINER);
  1017. X            }
  1018. X            else if(ntn[country].race==ELF){
  1019. X                ntn[country].powers=THE_VOID;
  1020. X                exenewmgk(THE_VOID);
  1021. X            }
  1022. X            else if(ntn[country].race==ORC){
  1023. X                ntn[country].powers=MI_MONST;
  1024. X                exenewmgk(MI_MONST);
  1025. X            }
  1026. X            else ntn[country].powers=1;
  1027. X            ntn[country].tfood=24000;
  1028. X            ntn[country].tiron=10000;
  1029. X            ntn[country].jewels=10000;
  1030. X            printf("nation %d: %s",cnum,line);
  1031. X            cnum++;
  1032. X            place();
  1033. X        }
  1034. X        if(fgets(line,80,fp)==NULL) done=1;
  1035. X    }
  1036. X    printf("all npc nations placed\n");
  1037. X#endif
  1038. X}
  1039. END_OF_makeworld.c
  1040. if test 19675 -ne `wc -c <makeworld.c`; then
  1041.     echo shar: \"makeworld.c\" unpacked with wrong size!
  1042. fi
  1043. # end of overwriting check
  1044. fi
  1045. if test -f npc.c -a "${1}" != "-c" ; then 
  1046.   echo shar: Will not over-write existing file \"npc.c\"
  1047. else
  1048. echo shar: Extracting \"npc.c\" \(22830 characters\)
  1049. sed "s/^X//" >npc.c <<'END_OF_npc.c'
  1050. X/*conquest is copyrighted 1986 by Ed Barlow.
  1051. X *  I spent a long time writing this code & I hope that you respect this.  
  1052. X *  I give permission to alter the code, but not to copy or redistribute
  1053. X *  it without my explicit permission.  If you alter the code, 
  1054. X *  please document changes and send me a copy, so all can have it.  
  1055. X *  This code, to the best of my knowledge works well,  but it is my first
  1056. X *  'C' program and should be treated as such.  I disclaim any
  1057. X *  responsibility for the codes actions (use at your own risk).  I guess
  1058. X *  I am saying "Happy gaming", and am trying not to get sued in the process.
  1059. X *                                                Ed
  1060. X */
  1061. X
  1062. X#include "header.h"
  1063. X#include <ctype.h>
  1064. X
  1065. Xextern FILE *fnews;
  1066. X
  1067. Xextern short country;
  1068. Xextern int attr[MAPX][MAPY];     /*sector attactiveness*/
  1069. Xextern short occ[MAPX][MAPY];
  1070. Xextern short movecost[MAPX][MAPY];
  1071. Xint peace;       /*is 8 if at peace, 12 if at war*/
  1072. X
  1073. X#ifdef NPC
  1074. Xnationrun()
  1075. X{
  1076. X    int loop,armynum;
  1077. X    int x,y,i,z;
  1078. X
  1079. X    prep();
  1080. X
  1081. X    /* is there an error*/
  1082. X    if((sct[ntn[country].capx][ntn[country].capy].owner==country)&&(sct[ntn[country].capx][ntn[country].capy].designation!=DCAPITOL)){
  1083. X        sct[ntn[country].capx][ntn[country].capy].designation=DCAPITOL;
  1084. X    }
  1085. X
  1086. X    /*go to war*/
  1087. X    for(x=1;x<MAXNTN;x++) {
  1088. X        /*if they at war with you go to war with them*/
  1089. X        if(ntn[x].dstatus[country]>=WAR) {
  1090. X            ntn[country].dstatus[x]=WAR;
  1091. X        }
  1092. X        /*else adjust diplomacy*/
  1093. X        else if((ntn[country].dstatus[x]!=UNMET)&&(ntn[country].dstatus[x]!=JIHAD)&&(ntn[country].dstatus[x]!=CONFEDERACY)){
  1094. X            if((ntn[x].tmil>4*ntn[country].tmil)&&(ntn[x].score>4*ntn[country].score)){
  1095. X                if(rand()%3==0)  ntn[country].dstatus[x]=WAR;
  1096. X                else if(rand()%8==0)  
  1097. X                    ntn[country].dstatus[x]=JIHAD;
  1098. X                else ntn[country].dstatus[x]++;
  1099. X            }
  1100. X            /*if 2* mil and 2* score then not like them*/
  1101. X            else if((ntn[x].tmil>2*ntn[country].tmil)&&(ntn[x].score>2*ntn[country].score)){
  1102. X                if(ntn[country].dstatus[x]!=WAR)
  1103. X                    if(ntn[x].race==ntn[country].race){
  1104. X                        if(rand()%10==0) ntn[country].dstatus[x]++;
  1105. X                    }
  1106. X                    else if(rand()%3==0) ntn[country].dstatus[x]++;
  1107. X            }
  1108. X            /*adjust based on your status with them*/
  1109. X            if(ntn[country].dstatus[x]!=WAR){
  1110. X                if(ntn[x].dstatus[country]>ntn[country].dstatus[x]){
  1111. X                    if(rand()%3==0) 
  1112. X                        ntn[country].dstatus[x]++;
  1113. X                }
  1114. X                else 
  1115. X                    if(ntn[x].dstatus[country]<ntn[country].dstatus[x]){
  1116. X                        if(rand()%3==0) 
  1117. X                        ntn[country].dstatus[x]--;
  1118. X                    }
  1119. X            }
  1120. X            if(rand()%4==0) ntn[country].dstatus[x]++;
  1121. X            else if(rand()%3==0) ntn[country].dstatus[x]--;
  1122. X        }
  1123. X        else if((ntn[country].dstatus[x]==CONFEDERACY)&&(ntn[x].dstatus[country]==CONFEDERACY)&&(ntn[country].race==ntn[x].race)){
  1124. X            if(ntn[x].active>=2) takeover(1,x);
  1125. X        }
  1126. X    }
  1127. X
  1128. X    /*move units */
  1129. X    /*are they at war with any normal countries*/
  1130. X    peace=0;
  1131. X    for(i=1;i<MAXNTN;i++) if(ntn[country].dstatus[i]>peace)
  1132. X        peace=ntn[country].dstatus[i];
  1133. X
  1134. X    if(peace<WAR){
  1135. X        peace=8;
  1136. X        pceattr();
  1137. X        for(armynum=1;armynum<MAXARM;armynum++)
  1138. X            if((ASOLD!=0)&&(ASTAT!=GARRISON)) armymove(armynum);
  1139. X    }
  1140. X    /*if war then attack &/or expand */
  1141. X    else {
  1142. X        peace=12;
  1143. X        /*are they attacking or defending */
  1144. X        for(x=0;x<MAXNTN;x++) if(ntn[country].dstatus[x]>HOSTILE){
  1145. X            if(100*(ntn[country].tmil*(ntn[country].aplus+100))/((ntn[country].tmil*(ntn[country].aplus+100))+(ntn[x].tmil*(ntn[x].dplus+100)))>rand()%100){
  1146. X                /*attacker*/
  1147. X                for(armynum=1;armynum<MAXARM;armynum++)
  1148. X                    if((ASOLD>0)&&(ASTAT!=GARRISON)) ASTAT=ATTACK;
  1149. X                atkattr();
  1150. X            }
  1151. X            /*defender*/
  1152. X            else {
  1153. X                for(armynum=1;armynum<MAXARM;armynum++)
  1154. X                    if((ASOLD>0)&&(ASTAT!=GARRISON)){
  1155. X                        if(ASOLD<350) ASTAT=DEFEND;
  1156. X                        else ASTAT=ATTACK;
  1157. X                    }
  1158. X                defattr();
  1159. X            }
  1160. X        }
  1161. X
  1162. X        for(armynum=1;armynum<MAXARM;armynum++)
  1163. X            if((ASOLD!=0)&&(ASTAT!=GARRISON)) armymove(armynum);
  1164. X    }
  1165. X
  1166. X    /*redesignate sectors*/
  1167. X    if(ntn[country].active!=1) for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
  1168. X        if((sct[x][y].owner==country)&&(todigit(sct[x][y].vegitation)!=0)) npcredes(x,y);
  1169. X
  1170. X    /*build forts in any cities*/
  1171. X    if(ntn[country].active!=1) for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
  1172. X        if(((sct[x][y].designation==DCITY)||(sct[x][y].designation==DCAPITOL))&&(sct[x][y].fortress<(sct[x][y].people%1000))&&(sct[x][y].fortress<5))
  1173. X            sct[x][y].fortress++;
  1174. X
  1175. X    /*redo mil*/
  1176. X    /*rate position -- any cities with no garison get one*/
  1177. X    if(ntn[country].active!=1) redomil();
  1178. X
  1179. X    /*buy new powers and/or new weapons*/
  1180. X    if(ntn[country].jewels > 2* JWL_MGK) {
  1181. X        loop=0;
  1182. X        for(armynum==0;armynum<=MAXPOWER;armynum++){
  1183. X            if(magic(country,armynum)==1) i++;
  1184. X        }
  1185. X        /*maximum of nine powers for NPC nations*/
  1186. X        if(i>NPCPOWERS) loop=1;
  1187. X        while(loop==0){
  1188. X            if((z=getmagic())!=1){
  1189. X                fprintf(fnews,"2.\tnation %s gets magic power number %d\n",ntn[country].name,z);
  1190. X                exenewmgk(z);
  1191. X                ntn[country].jewels-=JWL_MGK;
  1192. X                loop=1;
  1193. X            }
  1194. X        }
  1195. X
  1196. X    }
  1197. X    if(ntn[country].tiron >  4 * IRONORE * ntn[country].tmil){
  1198. X        ntn[country].aplus+=1;
  1199. X        ntn[country].dplus+=1;
  1200. X        ntn[country].tgold-=2*IRONORE * ntn[country].tmil;
  1201. X    }
  1202. X}
  1203. X
  1204. X/*calculate attractiveness when at peace*/
  1205. Xpceattr()
  1206. X{
  1207. X    int x,y,temp;
  1208. X    /*add around capital*/
  1209. X    for(x=ntn[country].capx-2;x<=ntn[country].capx+2;x++)
  1210. X        for(y=ntn[country].capy-2;y<=ntn[country].capy+2;y++)
  1211. X            if(sct[x][y].owner==0) attr[x][y]+=80;
  1212. X    /*add to attractiveness for unowned sectors*/
  1213. X    for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) if(sct[x][y].owner==0) {
  1214. X        /*temp stands for the distance from the capital*/
  1215. X        temp=0;
  1216. X        if(x>ntn[country].capx) temp+=x-ntn[country].capx;
  1217. X        else temp+=ntn[country].capx-x;
  1218. X        if(y>ntn[country].capy) temp+=y-ntn[country].capy;
  1219. X        else temp+=ntn[country].capy-y;
  1220. X        if(temp<3) attr[x][y]+=300-(50*temp);
  1221. X        else if(temp<20) attr[x][y]+=100;
  1222. X    }
  1223. X    else if((sct[x][y].owner==NNOMAD)||(sct[x][y].owner==NBARBARIAN)||(sct[x][y].owner==NPIRATE)) attr[x][y]+=100;
  1224. X    if(sct[ntn[country].capy][ntn[country].capy].owner!=country){
  1225. X        attr[ntn[country].capy][ntn[country].capy]=1000;
  1226. X    }
  1227. X}
  1228. X
  1229. X/*calculate attractiveness of attacking sectors*/
  1230. Xatkattr()
  1231. X{
  1232. X    int nation,armie,x,y,x1,x2,Y1,y2;
  1233. X
  1234. X    for(x=ntn[country].capx-2;x<=ntn[country].capx+2;x++)
  1235. X        for(y=ntn[country].capy-2;y<=ntn[country].capy+2;y++)
  1236. X            if(sct[x][y].owner==0) attr[x][y]+=80;
  1237. X
  1238. X    for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) if((sct[x][y].owner==0)||(sct[x][y].owner==NNOMAD)||(sct[x][y].owner==NBARBARIAN)||(sct[x][y].owner==NPIRATE)) attr[x][y]+=100;
  1239. X
  1240. X    /*adjust for each nation that you are at war with*/
  1241. X    for(nation=1;nation<MAXNTN;nation++) if((ntn[country].dstatus[nation]>=WAR)&&(ntn[country].active!=0)){
  1242. X
  1243. X        /*plus 1/2 men if in sector with their army*/
  1244. X        /*defend your capital if occupied, +50 more if with their army*/
  1245. X        for(armie=1;armie<MAXARM;armie++){
  1246. X            if(ntn[nation].arm[armie].sold > 0) {
  1247. X
  1248. X                attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold%10;
  1249. X
  1250. X                if((ntn[nation].arm[armie].xloc<=ntn[country].capx+2)&&(ntn[nation].arm[armie].yloc<=ntn[country].capy+2)&&(ntn[nation].arm[armie].xloc>=ntn[country].capx-2)&&(ntn[nation].arm[armie].yloc>=ntn[country].capy-2)){
  1251. X                attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold%5;
  1252. X                if((rand()%3==0)&&(ntn[country].dstatus[nation]<WAR))
  1253. X                    ntn[country].dstatus[nation]++;
  1254. X                if((ntn[nation].arm[armie].xloc==ntn[country].capx)&&(ntn[nation].arm[armie].yloc==ntn[country].capy)){
  1255. X                    if(ntn[country].dstatus[nation]==WAR)
  1256. X                    ntn[country].dstatus[nation]=JIHAD;
  1257. X                    if(ntn[nation].arm[armie].sold>2*ntn[country].arm[0].sold){
  1258. X                        attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold%2;
  1259. X                    }
  1260. X                    else attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold%5;
  1261. X                }
  1262. X                }
  1263. X            }
  1264. X        }
  1265. X
  1266. X        /*plus 40 if next to their capital */
  1267. X        for(x=ntn[nation].capx-1;x<=ntn[nation].capy+1;x++){
  1268. X            for(y=ntn[nation].capy-1;y<=ntn[nation].capy+1;y++){
  1269. X                if((x>0)&&(x<MAPX)&&(y>0)&&(y<MAPY)) attr[x][y]+=40;
  1270. X            }
  1271. X        }
  1272. X
  1273. X        /*plus 100 if on their capital*/
  1274. X        attr[ntn[nation].capx][ntn[nation].capy]+=100;
  1275. X
  1276. X        /*+60 if between the two capitals*/
  1277. X        if (ntn[nation].capx < ntn[country].capx){
  1278. X            x1=ntn[nation].capx;
  1279. X            x2=ntn[country].capx;
  1280. X        }
  1281. X        else {
  1282. X            x1=ntn[country].capx;
  1283. X            x2=ntn[nation].capx;
  1284. X        }
  1285. X        if (ntn[nation].capy < ntn[country].capy){
  1286. X            Y1=ntn[nation].capy;
  1287. X            y2=ntn[country].capy;
  1288. X        }
  1289. X        else {
  1290. X            Y1=ntn[country].capy;
  1291. X            y2=ntn[nation].capy;
  1292. X        }
  1293. X        for(x=x1;x<=x2;x++) for(y=Y1;y<=y2;y++) {
  1294. X            if((x>0)&&(x<MAPX)&&(y>0)&&(y<MAPY)) attr[x][y]+=60;
  1295. X        }
  1296. X
  1297. X        /*for each sector +60 if their sector*/
  1298. X        for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
  1299. X            if((sct[x][y].owner==nation)&&(occ[x][y]==0))
  1300. X                attr[x][y]+=100;
  1301. X            else if(sct[x][y].owner==nation) 
  1302. X                attr[x][y]+=60;
  1303. X    }
  1304. X    if(sct[ntn[country].capy][ntn[country].capy].owner!=country){
  1305. X        attr[ntn[country].capy][ntn[country].capy]=1000;
  1306. X    }
  1307. X}
  1308. X
  1309. Xdefattr()
  1310. X{
  1311. X    int nation,armie,x,y,x1,x2,y1,y2;
  1312. X
  1313. X    for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) if((sct[x][y].owner==0)||(sct[x][y].owner==NNOMAD)||(sct[x][y].owner==NBARBARIAN)||(sct[x][y].owner==NPIRATE)) attr[x][y]+=100;
  1314. X
  1315. X    for(x=ntn[country].capx-2;x<=ntn[country].capx+2;x++)
  1316. X        for(y=ntn[country].capy-2;y<=ntn[country].capy+2;y++)
  1317. X            if(sct[x][y].owner==0) attr[x][y]+=80;
  1318. X
  1319. X    for(nation=1;nation<MAXNTN;nation++) if((ntn[nation].active!=0)&&(ntn[country].dstatus[nation]>=WAR)) {
  1320. X
  1321. X        /*plus if near enemy army*/
  1322. X        /*plus 30 if next to their army*/
  1323. X        /*plus 60 if with their army*/
  1324. X        for(armie=1;armie<MAXARM;armie++) if(ntn[nation].arm[armie].sold > 0) {
  1325. X
  1326. X            attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold%10;
  1327. X
  1328. X            if((ntn[nation].arm[armie].xloc<=ntn[country].capx+2)&&(ntn[nation].arm[armie].yloc<=ntn[country].capy+2)&&(ntn[nation].arm[armie].xloc>=ntn[country].capx-2)&&(ntn[nation].arm[armie].yloc>=ntn[country].capy-2)){
  1329. X                attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold%5;
  1330. X                if((rand()%3==0)&&(ntn[country].dstatus[nation]<WAR))
  1331. X                    ntn[country].dstatus[nation]++;
  1332. X                if((ntn[nation].arm[armie].xloc==ntn[country].capx)&&(ntn[nation].arm[armie].yloc==ntn[country].capy)){
  1333. X                    if(ntn[country].dstatus[nation]==WAR)
  1334. X                    ntn[country].dstatus[nation]=JIHAD;
  1335. X                    if(ntn[nation].arm[armie].sold>2*ntn[country].arm[0].sold){
  1336. X                        attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold%2;
  1337. X                    }
  1338. X                    else attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold%5;
  1339. X                }
  1340. X            }
  1341. X        }
  1342. X
  1343. X
  1344. X        /*plus if strategic blocking sector*/
  1345. X        /*+60 if between the two capitals*/
  1346. X        if (ntn[nation].capx < ntn[country].capx){
  1347. X            x1=ntn[nation].capx;
  1348. X            x2=ntn[country].capx;
  1349. X        }
  1350. X        else {
  1351. X            x1=ntn[country].capx;
  1352. X            x2=ntn[nation].capx;
  1353. X        }
  1354. X        if (ntn[nation].capy < ntn[country].capy){
  1355. X            y1=ntn[nation].capy;
  1356. X            y2=ntn[country].capy;
  1357. X        }
  1358. X        else {
  1359. X            y1=ntn[country].capy;
  1360. X            y2=ntn[nation].capy;
  1361. X        }
  1362. X
  1363. X        for(x=x1;x<=x2;x++) for(y=y1;y<=y2;y++) {
  1364. X            if((x>0)&&(x<MAPX)&&(y>0)&&(y<MAPY)) attr[x][y]+=60;
  1365. X        }
  1366. X
  1367. X        /*plus 80 if near your capital */
  1368. X        for(x=ntn[country].capx-1;x<=ntn[country].capy+1;x++){
  1369. X            for(y=ntn[country].capy-1;y<=ntn[country].capy+1;y++){
  1370. X                if((x>0)&&(x<MAPX)&&(y>0)&&(y<MAPY)) attr[x][y]+=80;
  1371. X            }
  1372. X        }
  1373. X
  1374. X        /*plus based on defensive value*/
  1375. X        for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) {
  1376. X            if(movecost[x][y]==1) attr[x][y] += 50;
  1377. X            else if(movecost[x][y]<=3) attr[x][y] += 20;
  1378. X            else if(movecost[x][y]<=5) attr[x][y] += 10;
  1379. X
  1380. X            if((sct[x][y].designation==DCITY)&&((sct[x][y].owner==country)||(sct[x][y].owner==nation))){
  1381. X                attr[x][y] += 50;
  1382. X            }
  1383. X
  1384. X            /* plus 60 if they own and unoccupied*/
  1385. X            if((sct[x][y].owner==nation)&&(occ[x][y]==0)) attr[x][y]+=100;
  1386. X            else if(sct[x][y].owner==nation) attr[x][y]+=60;
  1387. X        }
  1388. X    }
  1389. X
  1390. X    if(sct[ntn[country].capy][ntn[country].capy].owner!=country){
  1391. X        attr[ntn[country].capy][ntn[country].capy]=1000;
  1392. X    }
  1393. X}
  1394. X#endif
  1395. X
  1396. X/*ntn 1 is nation you are updating*/
  1397. Xnewdip(ntn1,ntn2)
  1398. X{
  1399. X    if(ntn[ntn1].active<2) {
  1400. X        if(ntn[ntn1].dstatus[ntn2]==UNMET)
  1401. X            ntn[ntn1].dstatus[ntn2]=NEUTRAL;
  1402. X    }
  1403. X    else if(ntn[ntn1].race==ntn[ntn2].race){
  1404. X        if(rand()%5<3) ntn[ntn1].dstatus[ntn2]=FRIENDLY;
  1405. X        else if(rand()%2==0) ntn[ntn1].dstatus[ntn2]=ALLIED;
  1406. X        else ntn[ntn1].dstatus[ntn2]=NEUTRAL;
  1407. X    }
  1408. X    else switch(ntn[ntn1].race) {
  1409. X    case DWARF:
  1410. X        switch(ntn[ntn2].race) {
  1411. X        case ELF:
  1412. X            ntn[ntn1].dstatus[ntn2]=HOSTILE;
  1413. X            break;
  1414. X        case HUMAN:
  1415. X            ntn[ntn1].dstatus[ntn2]=NEUTRAL;
  1416. X            break;
  1417. X        case ORC:
  1418. X        default:
  1419. X            ntn[ntn1].dstatus[ntn2]=WAR;
  1420. X            break;
  1421. X        }
  1422. X        break;
  1423. X    case ELF:
  1424. X        switch(ntn[ntn2].race) {
  1425. X        case DWARF:
  1426. X            ntn[ntn1].dstatus[ntn2]=HOSTILE;
  1427. X            break;
  1428. X        case HUMAN:
  1429. X            ntn[ntn1].dstatus[ntn2]=NEUTRAL;
  1430. X            break;
  1431. X        case ORC:
  1432. X        default:
  1433. X            ntn[ntn1].dstatus[ntn2]=WAR;
  1434. X            break;
  1435. X        }
  1436. X        break;
  1437. X    case ORC:
  1438. X        switch(ntn[ntn2].race) {
  1439. X        case HUMAN:
  1440. X            ntn[ntn1].dstatus[ntn2]=NEUTRAL;
  1441. X            break;
  1442. X        case DWARF:
  1443. X        case ELF:
  1444. X        default:
  1445. X            ntn[ntn1].dstatus[ntn2]=WAR;
  1446. X            break;
  1447. X        }
  1448. X        break;
  1449. X    case HUMAN:
  1450. X        switch(ntn[ntn2].race) {
  1451. X        case DWARF:
  1452. X        case ELF:
  1453. X            ntn[ntn1].dstatus[ntn2]=NEUTRAL;
  1454. X            break;
  1455. X        case ORC:
  1456. X            ntn[ntn1].dstatus[ntn2]=HOSTILE;
  1457. X            break;
  1458. X        default:
  1459. X            ntn[ntn1].dstatus[ntn2]=WAR;
  1460. X            break;
  1461. X        }
  1462. X        break;
  1463. X    default:
  1464. X        ntn[ntn1].dstatus[ntn2]=WAR;
  1465. X        break;
  1466. X    }
  1467. X}
  1468. X
  1469. X/*destroy nation--special case if capital not owned by other nation*/
  1470. Xdestroy()
  1471. X{
  1472. X    short armynum, nvynum;
  1473. X    int i, x, y;
  1474. X    fprintf(fnews,"1.\tDESTROY NATION %s",ntn[country].name);
  1475. X    if(country!=sct[ntn[country].capx][ntn[country].capy].owner){
  1476. X        fprintf(fnews,"\t(their capitol is owned by %s)\n",ntn[sct[ntn[country].capx][ntn[country].capy].owner].name);
  1477. X        /*get +5% to combat skill*/
  1478. X        ntn[sct[ntn[country].capx][ntn[country].capy].owner].aplus+=5;
  1479. X    }
  1480. X    else fprintf(fnews,"\t(they own their capitol)\n");
  1481. X
  1482. X    ntn[country].active=0;
  1483. X    for(armynum=0;armynum<MAXARM;armynum++) if(ASOLD>0) {
  1484. X        if(ntn[sct[AXLOC][AYLOC].owner].race==ntn[country].race)
  1485. X            sct[AXLOC][AYLOC].people+=ASOLD;
  1486. X        ASOLD=0;
  1487. X    }
  1488. X    for(nvynum=0;nvynum<MAXNAVY;nvynum++) {
  1489. X        NMER=0;
  1490. X        NWAR=0;
  1491. X    }
  1492. X    for(i=0;i<MAXNTN;i++) {
  1493. X        ntn[i].dstatus[country]=UNMET;
  1494. X        ntn[country].dstatus[i]=UNMET;
  1495. X    }
  1496. X
  1497. X    /*if take them you get their gold*/
  1498. X    if(country!=sct[ntn[country].capx][ntn[country].capy].owner){
  1499. X        if(ntn[country].tgold>0) ntn[sct[ntn[country].capx][ntn[country].capy].owner].tgold+=ntn[country].tgold;
  1500. X        if(ntn[country].jewels>0) ntn[sct[ntn[country].capx][ntn[country].capy].owner].jewels+=ntn[country].jewels;
  1501. X        if(ntn[country].tiron>0) ntn[sct[ntn[country].capx][ntn[country].capy].owner].tiron+=ntn[country].tiron;
  1502. X        if(ntn[country].tfood>0) ntn[sct[ntn[country].capx][ntn[country].capy].owner].tfood+=ntn[country].tfood;
  1503. X    }
  1504. X
  1505. X    /*if god destroys then kill all population*/
  1506. X    if(country==sct[ntn[country].capx][ntn[country].capy].owner){
  1507. X        for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) if(sct[x][y].owner==country) {
  1508. X            sct[x][y].people=0;
  1509. X            sct[x][y].owner=0;
  1510. X            if(isdigit(sct[x][y].vegitation)!=0)
  1511. X                sct[x][y].designation=DNODESIG;
  1512. X        }
  1513. X    }
  1514. X    /*slowly take over and all people flee*/
  1515. X    else if(ntn[sct[ntn[country].capx][ntn[country].capy].owner].race!=ntn[country].race){
  1516. X        for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) if(sct[x][y].owner==country) {
  1517. X            /*all kinds of refugees to neighboring countries*/
  1518. X            flee(x,y,1);
  1519. X            sct[x][y].people=0;
  1520. X            sct[x][y].owner=0;
  1521. X            if(isdigit(sct[x][y].vegitation)!=0)
  1522. X                sct[x][y].designation=DNODESIG;
  1523. X        }
  1524. X    }
  1525. X    /*else same race, so give all land to conqueror*/
  1526. X    else {
  1527. X        for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) if(sct[x][y].owner==country){
  1528. X            sct[x][y].owner=sct[ntn[country].capx][ntn[country].capy].owner;
  1529. X            if(isdigit(sct[x][y].vegitation)!=0)
  1530. X                sct[x][y].designation=DNODESIG;
  1531. X        }
  1532. X    }
  1533. X    return;
  1534. X}
  1535. X
  1536. Xmonster()
  1537. X{
  1538. X    short nvynum,armynum;
  1539. X    int x, y, done, j;
  1540. X
  1541. X    /*move nomads randomly until within 2 of city then attack*/
  1542. X    country=NNOMAD;
  1543. X    for(armynum=0;armynum<MAXARM;armynum++) if(ASOLD>0){
  1544. X        x=AXLOC+rand()%4-2;
  1545. X        y=AYLOC+rand()%4-2;
  1546. X        if((x>0)&&(x<MAPX)&&(y>0)&&(y<MAPY)&&(sct[x][y].altitude!=PEAK)&&(sct[x][y].altitude!=WATER)) {
  1547. X            AXLOC=x;
  1548. X            AYLOC=y;
  1549. X            done=0;
  1550. X            /*if owned & unoccupied you take & people flee*/
  1551. X            if(sct[x][y].owner!=0) for(j=0;j<MAXARM;j++) if((ntn[sct[x][y].owner].arm[j].xloc==x)&&(ntn[sct[x][y].owner].arm[j].yloc==y)&&(ntn[sct[x][y].owner].arm[j].sold>0)) done=1;
  1552. X
  1553. X            /*nomads take sector if done=0*/
  1554. X            if(done==0){
  1555. X                if(sct[x][y].owner==0)
  1556. X                    fprintf(fnews,"3.\tnomads take sector %d,%d\n",x,y);
  1557. X                else fprintf(fnews,"3.\tnomads capture sector %d,%d\n",x,y);
  1558. X                if(sct[x][y].owner!=0) flee(x,y,1);
  1559. X                sct[x][y].owner=NNOMAD;
  1560. X                sct[x][y].designation=DDEVASTATED;
  1561. X            }
  1562. X        }
  1563. X    }
  1564. X    else {
  1565. X        /*place a new Nomad army*/
  1566. X        x=(rand()%MAPX-8)+4;
  1567. X        y=(rand()%MAPY-8)+4;
  1568. X        if((rand()%4==0)&&(sct[x][y].altitude!=PEAK)&&(sct[x][y].altitude!=WATER)) {
  1569. X            AXLOC=x;
  1570. X            AYLOC=y;
  1571. X            ASOLD=100+100*rand()%10;
  1572. X            ASTAT=ATTACK;
  1573. X        }
  1574. X    }
  1575. X    fprintf(fnews,"2.\t%s are updated\n",ntn[NPIRATE].name);
  1576. X    /*if pirate fleet within 3 attack if outnumber any fleets */
  1577. X    for(nvynum=0;nvynum<MAXNAVY;nvynum++){
  1578. X    for(x=1;x<MAXNTN;x++) for(y=0;y<MAXNAVY;y++)
  1579. X    if((ntn[x].nvy[y].xloc-NXLOC<2)&&(ntn[x].nvy[y].xloc-NXLOC>(-2))&&
  1580. X    (ntn[x].nvy[y].yloc-NYLOC<2)&&(ntn[x].nvy[y].yloc-NYLOC>(-2))&&
  1581. X    (sct[ntn[x].nvy[y].xloc][ntn[x].nvy[y].yloc].altitude==WATER)){
  1582. X        NXLOC= ntn[x].nvy[y].xloc;
  1583. X        NYLOC= ntn[x].nvy[y].yloc;
  1584. X    }
  1585. X    /*add one warship to random pirate fleet*/
  1586. X    if((NWAR>0)&&(rand()%3==0)) NWAR++;
  1587. X    }
  1588. X}
  1589. X
  1590. Xnpcredes(x,y)
  1591. X{
  1592. X    int food;
  1593. X    /*large enough for a city now?*/
  1594. X    if(((sct[x][y].people*(CITYLIMIT+(ntn[sct[x][y].owner].tsctrs/3))>ntn[sct[x][y].owner].tciv)||((ntn[sct[x][y].owner].tciv<30000)&&(sct[x][y].people>1000)))&&(ntn[sct[x][y].owner].tfood>ntn[sct[x][y].owner].tciv*2)){
  1595. X        if((rand()%2==0)&&((sct[x][y].designation==DFARM)||(sct[x][y].designation==DGOLDMINE)||(sct[x][y].designation==DMINE)))
  1596. X            sct[x][y].designation=DCITY;
  1597. X    }
  1598. X    /*not large enough for city and not enough food*/
  1599. X    else if((sct[x][y].designation==DCITY)&&(ntn[sct[x][y].owner].tfood<ntn[sct[x][y].owner].tciv*2)&&(todigit(sct[x][y].vegitation)>5)){
  1600. X        sct[x][y].designation=DFARM;
  1601. X        food=todigit(sct[x][y].vegitation)*sct[x][y].people;
  1602. X        ntn[sct[x][y].owner].tfood += food;
  1603. X        ntn[sct[x][y].owner].tgold += food*TAXFOOD/100-(sct[x][y].people * TAXCITY/100);
  1604. X    }
  1605. X    /*not large enough for a city but enough food*/
  1606. X    else if((sct[x][y].designation==DCITY)&&(rand()%5==0)){
  1607. X        sct[x][y].designation=DFARM;
  1608. X        food=todigit(sct[x][y].vegitation)*sct[x][y].people;
  1609. X        ntn[sct[x][y].owner].tfood += food;
  1610. X        ntn[sct[x][y].owner].tgold += food*TAXFOOD/100-(sct[x][y].people * TAXCITY/100);
  1611. X    }
  1612. X
  1613. X    /*what if it is not a city*/
  1614. X    if((sct[x][y].designation!=DCITY)&&(sct[x][y].designation!=DCAPITOL)) {
  1615. X        sct[x][y].designation=DFARM;
  1616. X        /*crisis situation -- need more food producers*/
  1617. X        if(ntn[sct[x][y].owner].tfood<=2*ntn[sct[x][y].owner].tciv){
  1618. X            if(sct[x][y].iron>5)
  1619. X                sct[x][y].designation=DMINE;
  1620. X            if((sct[x][y].gold>5)&&(sct[x][y].gold>sct[x][y].iron-2))
  1621. X                sct[x][y].designation=DGOLDMINE;
  1622. X        }
  1623. X        /*non crisis situation -- need more food producers*/
  1624. X        else {
  1625. X            if(sct[x][y].iron>2)
  1626. X                sct[x][y].designation=DMINE;
  1627. X            if((sct[x][y].gold>2)&&(sct[x][y].gold>sct[x][y].iron-2))
  1628. X                sct[x][y].designation=DGOLDMINE;
  1629. X        }
  1630. X    }
  1631. X}
  1632. X
  1633. Xredomil()
  1634. X{
  1635. X    short x,y,armynum;
  1636. X    int diff, i, free, done;
  1637. X
  1638. X    /*make sure enough men in army 0 -- garrison duty in capital*/
  1639. X    armynum=0;
  1640. X    ASTAT=GARRISON;
  1641. X    AXLOC=ntn[country].capx;
  1642. X    AYLOC=ntn[country].capy;
  1643. X
  1644. X    /*Ideally ASOLD(0)*MILINCAP=tmil*peace/10*/
  1645. X    /*MILRATIO ratio mil:civ for non player countries*/
  1646. X    /*MILINCAP ratio (mil in cap):mil for NPCs*/
  1647. X    if(ASOLD*MILINCAP<.9*ntn[country].tmil*peace/10){
  1648. X        /*too few soldiers on garrison*/
  1649. X        /*diff is number to change mil in cap (>0)*/
  1650. X        diff=(ntn[country].tmil*peace/(10*MILINCAP))-ASOLD;
  1651. X
  1652. X        if(diff<ntn[country].tiron*10) diff=ntn[country].tiron*10;
  1653. X        if(ntn[country].tgold<0L) diff=0;
  1654. X
  1655. X        if(diff>sct[ntn[country].capx][ntn[country].capy].people)
  1656. X            diff=sct[ntn[country].capx][ntn[country].capy].people/2;
  1657. X
  1658. X        sct[ntn[country].capx][ntn[country].capy].people-=diff;
  1659. X        ASOLD+=diff;
  1660. X        ntn[country].tciv-=diff;
  1661. X        ntn[country].tmil+=diff;
  1662. X        ntn[country].tgold-=diff*ENLISTCOST;
  1663. X        ntn[country].tiron-=diff*10;
  1664. X    }
  1665. X    /*else split garrison army if 1.25* needed number*/
  1666. X    else if(ASOLD*MILINCAP>1.1*ntn[country].tmil*peace/10){
  1667. X        diff=ASOLD-(1.25*ntn[country].tmil*peace/(10*MILINCAP));
  1668. X        free=0;
  1669. X        ASOLD-=diff;
  1670. X        ntn[country].tciv-=diff;
  1671. X        ntn[country].tmil+=diff;
  1672. X        sct[ntn[country].capx][ntn[country].capy].people+=diff;
  1673. X    }
  1674. X
  1675. X    /*build ships and/or armies*/
  1676. X    done=0;
  1677. X    /*if tmil*MILRATIO<tciv build a single new army in the capital if possible*/
  1678. X    if((ntn[country].tmil*MILRATIO<.8*ntn[country].tciv*peace/10)&&(ntn[country].tgold>0L)) for(armynum=1;armynum<MAXARM;armynum++) if((done==0)&&(ASOLD==0)) {
  1679. X        done=1;
  1680. X        ASOLD=(ntn[country].tciv*peace/(10*MILRATIO))-ntn[country].tmil;
  1681. X        if(ASOLD>ntn[country].tiron*10) ASOLD= ntn[country].tiron/10;
  1682. X        if(2*ASOLD>sct[ntn[country].capx][ntn[country].capy].people)
  1683. X            ASOLD=sct[ntn[country].capx][ntn[country].capy].people/2;
  1684. X        ntn[country].tiron-=ASOLD*10;
  1685. X        AXLOC= ntn[country].capx;
  1686. X        AYLOC= ntn[country].capy;
  1687. X        ntn[country].tmil += ASOLD;
  1688. X        ntn[country].tciv -= ASOLD;
  1689. X        ntn[country].tgold-=ASOLD*ENLISTCOST;
  1690. X        sct[AXLOC][AYLOC].people-=ASOLD;
  1691. X        ASTAT= DEFEND;
  1692. X        AMOVE=0;
  1693. X    }
  1694. X
  1695. X    /*disband ships and/or armies*/
  1696. X    if(ntn[country].tmil*MILRATIO>1.2*ntn[country].tciv*peace/10){
  1697. X        /*disband a pseudo-random army*/
  1698. X        done=0;
  1699. X        diff=ntn[country].tmil-(1.2*ntn[country].tciv*peace/(10*MILRATIO));
  1700. X        for(armynum=1;armynum<MAXARM;armynum++)
  1701. X            if((done==0)&&(sct[AXLOC][AYLOC].owner==country)&&((sct[AXLOC][AYLOC].gold>5)||(sct[AXLOC][AYLOC].iron>5))&&(rand()%5==0)&&(ASOLD<diff)){
  1702. X                sct[AXLOC][AYLOC].people+=ASOLD;
  1703. X                ntn[country].tmil -= ASOLD;
  1704. X                ntn[country].tciv += ASOLD;
  1705. X                ASOLD=0;
  1706. X                if(ntn[country].tmil*MILRATIO>1.2*ntn[country].tciv*peace/10) done=1;
  1707. X            }
  1708. X    }
  1709. X
  1710. X    /*resize armies */
  1711. X    /*maximum npc army is 200 or tmil/20, minimum is 50*/
  1712. X    for(armynum=1;armynum<MAXARM;armynum++){
  1713. X        if((ASOLD>200)&&(ASOLD>ntn[country].tmil/20)) {
  1714. X            free=0;
  1715. X            for(i=1;i<MAXARM;i++){
  1716. X                if((free==0)&&(ntn[country].arm[i].sold==0)){
  1717. X                    free=1;
  1718. X                    ASOLD/=2;
  1719. X                    ntn[country].arm[i].sold  = ASOLD;
  1720. X                    ntn[country].arm[i].smove = AMOVE;
  1721. X                    ntn[country].arm[i].stat  = DEFEND;
  1722. X                    ntn[country].arm[i].xloc  = AXLOC;
  1723. X                    ntn[country].arm[i].yloc  = AYLOC;
  1724. X                }
  1725. X            }
  1726. X        }
  1727. X    /*minimum npc army is 50, merge them*/
  1728. X        else if(ASOLD<50) {
  1729. X            free=0;
  1730. X            for(i=1;i<MAXARM;i++){
  1731. X                if((ntn[country].arm[i].sold>0)&&(ntn[country].arm[i].xloc==AXLOC)&&(ntn[country].arm[i].yloc==AYLOC)&&(i!=armynum)&&(free==0)){
  1732. X                    free=1;
  1733. X                    ntn[country].arm[i].sold += ASOLD;
  1734. X                    ASOLD=0;
  1735. X                }
  1736. X            }
  1737. X        }
  1738. X    }
  1739. X
  1740. X    for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) 
  1741. X    if((sct[x][y].owner==country)&&(sct[x][y].designation==DCITY)){
  1742. X        free=0;
  1743. X        for(armynum=0;armynum<MAXARM;armynum++){
  1744. X            if((AXLOC==x)&&(AYLOC==y)) free=1;
  1745. X        }
  1746. X        /*move army in*/
  1747. X        if(free==0){
  1748. X            for(armynum=1;armynum<MAXARM;armynum++)
  1749. X                if((abs(AXLOC-x)<=1)&&(abs(AYLOC-y)<=1))
  1750. X                    free=armynum;
  1751. X            if(free>0){
  1752. X                armynum=free;
  1753. X                AXLOC=x;
  1754. X                AYLOC=y;
  1755. X            }
  1756. X        }
  1757. X    }
  1758. X}
  1759. END_OF_npc.c
  1760. if test 22830 -ne `wc -c <npc.c`; then
  1761.     echo shar: \"npc.c\" unpacked with wrong size!
  1762. fi
  1763. # end of overwriting check
  1764. fi
  1765. echo shar: End of archive 1 \(of 5\).
  1766. cp /dev/null ark1isdone
  1767. MISSING=""
  1768. for I in 1 2 3 4 5 ; do
  1769.     if test ! -f ark${I}isdone ; then
  1770.     MISSING="${MISSING} ${I}"
  1771.     fi
  1772. done
  1773. if test "${MISSING}" = "" ; then
  1774.     echo You have unpacked all 5 archives.
  1775.     rm -f ark[1-9]isdone
  1776. else
  1777.     echo You still need to unpack the following archives:
  1778.     echo "        " ${MISSING}
  1779. fi
  1780. ##  End of shell archive.
  1781. exit 0
  1782.